﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;

namespace LLK_WG
{
    public partial class Form1 : Form
    {
        #region  原单初始代码
        //引用API函数
        //[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        //static extern IntPtr FindWindow(string strClass, string strWindow);

        //[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        //static extern IntPtr EnumChildWindows(IntPtr hWndParent, CallBack lpEnumFunc, int lParam);

        //[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        //static extern int GetWindowRect(IntPtr hwnd, ref RECT lpRect);

        //[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        //static extern int SetCursorPos(int x, int y);

        //[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        //static extern bool GetCursorPos(ref POINT lpPoint);

        //[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        //static extern int SetForegroundWindow(IntPtr hwnd);

        //[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        //static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
        //public const int MOUSEEVENTF_LEFTDOWN = 0x2;
        //public const int MOUSEEVENTF_LEFTUP = 0x4;

        //[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        //static extern int GetWindowText(IntPtr hwnd, string lpString, int cch);

        //[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        //static extern int GetWindowThreadProcessId(IntPtr id, out int pid);

        //[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        //public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);
        //public const int PROCESS_ALL_ACCESS = 0x1F0FFF; //0x001F0FFF;
        //public const int PROCESS_VM_OPERATION = 0x0008;
        //public const int PROCESS_VM_READ = 0x0010;
        //public const int PROCESS_VM_WRITE = 0x0020;

        //[DllImport("kernel32.dll", ExactSpelling = true)]
        //internal static extern IntPtr GetCurrentProcess();

        //[DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
        //internal static extern bool OpenProcessToken(IntPtr h, int acc, ref IntPtr phtok);

        //[DllImport("advapi32.dll", SetLastError = true)]
        //internal static extern bool LookupPrivilegeValue(string host, string name, ref long pluid);

        //[DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
        //internal static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall,
        //ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen);


        //internal const int SE_PRIVILEGE_ENABLED = 0x00000002;
        //internal const int TOKEN_QUERY = 0x00000008;
        //internal const int TOKEN_ADJUST_PRIVILEGES = 0x00000020;
        //internal const string SE_SHUTDOWN_NAME = "SeShutdownPrivilege";
        //internal const int EWX_LOGOFF = 0x00000000;
        //internal const int EWX_SHUTDOWN = 0x00000001;
        //internal const int EWX_REBOOT = 0x00000002;
        //internal const int EWX_FORCE = 0x00000004;
        //internal const int EWX_POWEROOF = 0x00000008;
        //internal const int EWX_FORCEIFHUNG = 0x00000010;

        //[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        //public static extern int CloseHandle(IntPtr hProcess);

        //[DllImport("Kernel32.dll")]
        //public static extern uint GetLastError();

        //[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        //static extern bool ReadProcessMemory(int hProcess, int lpBaseAddress, out int lpBuffer, int nSize, out int lpNumberOfBytesRead);

        //[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        //public static extern bool ReadProcessMemory(int hProcess, int lpBaseAddress, byte[,] lpBuffer, int nSize, out int lpNumberOfBytesRead);
        //hProcess为远程进程的句柄
        //lpBaseAddress用于指明远程进程中的地址
        //lpBuffer是本地进程中的内存地址
        //nSize是需要传送的字节数
        //lpNumberOfBytesRead和lpNumberOfBytesWritten用于指明实际传送的字节数.当函数返回时，可以查看这两个参数的值

        //[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        //static extern int GetWindowTextLength(IntPtr hwnd);
        //string gameCaption = "QQ游戏 - 连连看角色版";

        //public struct RECT
        //{
        //    public int Left;
        //    public int Top;
        //    public int Right;
        //    public int Bottom;
        //}

        //public struct POINT
        //{
        //    public int x;
        //    public int y;
        //}

       // public static int nCount;

      

      

        //internal struct TokPriv1Luid
        //{
        //    public int Count;
        //    public long Luid;
        //    public int Attr;
        //}

        // public struct TOKEN_PRIVILEGES { 
        //      DWORD PrivilegeCount; 
        //     LUID_AND_ATTRIBUTES Privileges[]; 
        //} TOKEN_PRIVILEGES, *PTOKEN_PRIVILEGES;

        #endregion
        public Form1()
        {
            InitializeComponent();
        }
        
        Class1 cl = new Class1();
        private void button1_Click(object sender, EventArgs e)
        {
            cl.startGame();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            button7.Text = "挂机";
            timer1.Stop();
            timer1.Interval = 1;
            timer1.Start();
            timer2.Interval=3000;
            timer2.Start();
            
        }

        private void button6_Click(object sender, EventArgs e)
        {
            cl.clearPair();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
           
        }

        private void button7_Click(object sender, EventArgs e)
        {
            if (button7.Text == "挂机")
            {
                button7.Text="停止挂机";
                timer1.Interval = trackBar1.Value;
                timer1.Start();
            }
            else if (button7.Text == "停止挂机")
            {
                button7.Text = "挂机";
                timer1.Stop();
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            cl.clearPair();
            
        }

        private void trackBar1_ValueChanged(object sender, EventArgs e)
        {
            timer1.Stop();
            timer1.Interval = trackBar1.Value;
            timer1.Start();
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            timer1.Stop();
            timer2.Stop();
        }

        
    }
}
